package com.cpsdna.util;

import com.cpsdna.bean.user.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Jianghao on 2017/3/17.
 *
 * @author Howe(howechiang@gmail.com)
 */
public class SessionManger {

    public static boolean checkLogin(HttpServletRequest req) {

        return getCurrentUser(req) != null;
    }

    public static User getCurrentUser(HttpServletRequest req) {

        HttpSession session = req.getSession(false);
        if (session != null) {
            Object obj = session.getAttribute(User.USER_SESSION_KEY);
            if (obj != null)
                return (User) obj;
            else
                return null;
        } else
            return null;
    }

}
